package com.koron.order.repair.controller;

import com.koron.bean.base.Response;
import com.koron.order.common.bean.po.OrderAccept;
import com.koron.order.common.controller.OrderAcceptController;
import com.koron.order.repair.bean.entity.RepairStatus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName RepairAccept
 * @description
 * @Author zhouj
 * @Date 2021/10/15 18:50
 */
@Slf4j
@RequestMapping("/repair/orderAccept/")
@RestController
@Api(tags = "计划检修工单执行信息")
public class RepairAcceptController extends OrderAcceptController {

    @Autowired
    RepairController repairController;

    @Override
    @ApiOperation(value = "新增 ")
    @PostMapping("saveAcceptInfo")
    public Response<Integer> saveAcceptInfo(@Validated @RequestBody OrderAccept orderAccept) {
        Response<Integer> insert = super.saveAcceptInfo(orderAccept);

        if (orderAccept.getIsCommit()) {
            repairController.submitRepair(orderAccept.getOrderId(), RepairStatus.ARCHIVED.getStatus());
        }

        return insert;
    }
}
